﻿@page "/PivotGrid"

<DemoPageSectionComponent Id="PivotGrid-Overview">
    @inject ISalesInfoDataProvider Sales
    @layout DataProviderAccessArea<ISalesInfoDataProvider>

    @if(GridData == null) {
        <p><em>Loading...</em></p>
    } else {
        <DxPivotGrid Data="@GridData">
            <DxPivotGridField Field="@nameof(SaleInfo.Region)" SortOrder="PivotGridSortOrder.Ascending" Area="PivotGridFieldArea.Row" />
            <DxPivotGridField Field="@nameof(SaleInfo.Country)" Area="PivotGridFieldArea.Row" />
            <DxPivotGridField Field="@nameof(SaleInfo.City)" Area="PivotGridFieldArea.Row" />
            <DxPivotGridField Field="@nameof(SaleInfo.Date)" GroupInterval="PivotGridGroupInterval.Year" Area="PivotGridFieldArea.Column" Caption="Year" />
            <DxPivotGridField Field="@nameof(SaleInfo.Date)" GroupInterval="PivotGridGroupInterval.Quarter" Area="PivotGridFieldArea.Column" Caption="Quarter">
                <HeaderTemplate>@string.Format("Q{0}", context)</HeaderTemplate>
            </DxPivotGridField>
            <DxPivotGridField Field="@nameof(SaleInfo.Amount)" Area="PivotGridFieldArea.Data" SummaryType="PivotGridSummaryType.Sum" />
            <DxPivotGridField Field="@nameof(SaleInfo.OrderId)" Caption="Count" Area="PivotGridFieldArea.Data" SummaryType="PivotGridSummaryType.Count" />
        </DxPivotGrid>
    }
    @code {
        IEnumerable<SaleInfo> GridData;

        protected override async Task OnInitializedAsync() {
            GridData = await Sales.GetSalesAsync();
        }
    }
</DemoPageSectionComponent>

